package com.uniandes.edu.co.interfaz.ciclo;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.SwingUtilities;

import com.uniandes.edu.co.dto.Requerimiento;
import com.uniandes.edu.co.dto.Tsp;
import com.uniandes.edu.co.excepciones.ExcepcionExiste;
import com.uniandes.edu.co.excepciones.ExcepcionVacio;


/**
 * This code was edited or generated using CloudGarden's Jigloo
 * SWT/Swing GUI Builder, which is free for non-commercial
 * use. If Jigloo is being used commercially (ie, by a corporation,
 * company or business for any purpose whatever) then you
 * should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details.
 * Use of Jigloo implies acceptance of these licensing terms.
 * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
 * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
 * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
@SuppressWarnings("serial")
public class InterfazModificarRequerimiento extends javax.swing.JFrame {
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JButton jButton1;
	private JButton jButton2;
	private JTextArea jTextArea1;
	private JScrollPane jScrollPane1;
	private JTextField jTextField1;
	public LinkedList<Requerimiento> listadoR;

	/**
	 * Auto-generated main method to display this JFrame
	 */
	public static void main(final String[] args,final LinkedList<Requerimiento> listadoRequermiento, final String idrequerimiento) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				InterfazModificarRequerimiento inst = new InterfazModificarRequerimiento(listadoRequermiento, idrequerimiento,args);
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}

	public InterfazModificarRequerimiento( LinkedList<Requerimiento> listadoRequermiento, final String idrequerimiento,String[] args) {
		super();
		initGUI(listadoRequermiento,idrequerimiento,args);

	}

	private void initGUI(  final LinkedList<Requerimiento> listadoRequermiento, final String idrequerimiento,final String[] args) {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			listadoR=listadoRequermiento;
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("REQUERIMIENTOS");
				jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
				jLabel1.setHorizontalTextPosition(SwingConstants.CENTER);
				jLabel1.setFont(new java.awt.Font("Tahoma",1,14));
				jLabel1.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
				jLabel1.setBounds(44, 26, 386, 26);
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("Id Requerimiento");
				jLabel2.setBounds(44, 72, 106, 23);
				jLabel2.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			}
			{
				jLabel3 = new JLabel();
				getContentPane().add(jLabel3);
				jLabel3.setText("Descripcion");
				jLabel3.setBounds(44, 100, 106, 23);
				jLabel3.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			}
			{
				jTextField1 = new JTextField();
				getContentPane().add(jTextField1);
				jTextField1.setBounds(168, 72, 262, 23);
				jTextField1.setEditable(false);
			}
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("Modificar");
				jButton1.setBounds(256, 215, 152, 23);
				jButton1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						try {
							Tsp.getSingleton().modificarRequerimiento(jTextField1.getText(), jTextArea1.getText(), listadoR);
							dispose();
							InterfazAgregarCiclo.main(args, listadoR);
						} catch (ExcepcionVacio e) {
							
							JOptionPane.showMessageDialog(null, e.getMessage());
						} catch (ExcepcionExiste e) {
							JOptionPane.showMessageDialog(null, e.getMessage());
						}
					}
				});
			}
			{
				jScrollPane1 = new JScrollPane();
				getContentPane().add(jScrollPane1);
				jScrollPane1.setBounds(168, 101, 262, 102);
				{
					jTextArea1 = new JTextArea();
					jScrollPane1.setViewportView(jTextArea1);
				}
			}
			{
				jButton2 = new JButton();
				getContentPane().add(jButton2);
				jButton2.setText("Regresar");
				jButton2.setBounds(93, 214, 152, 26);
				jButton2.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						dispose();
						InterfazAgregarCiclo.main(args, listadoR);
					}
				});
			}
			Requerimiento requerimiento=Tsp.getSingleton().obtenerRequerimiento(idrequerimiento, listadoR);
			jTextField1.setText(requerimiento.getIdRequerimiento());
			jTextArea1.setText(requerimiento.getDetalleRequerimiento());
			pack();
			this.setSize(495, 300);
		} catch (Exception e) {
			//add your error handling code here
			e.printStackTrace();
		}
	}

}
